package com.zhdl.network.servertcp;

import cn.hutool.core.util.HexUtil;
import com.project.command.faq.queues.data.ControlInstructionPerformData;
import com.project.command.instruction.service.InstructionSendService;
import com.project.command.instruction.strategy.abs.AbsAfterControlCommand;
import com.project.command.instruction.strategy.process.data.AfterStrategyParam;
import com.zhdl.network.modbusrtu.dto.ModbusDto;
import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.zhdl.network.servertcp.HandAfterDefaultService.HAND_AFTER_DEFAULT_SERVICE;


/**
 * 手操器默认收到数据处理策略
 *
 * @Author: zhangyy
 * @Email: zhang10092009@hotmail.com
 * @Date: 2023/4/18 10:58:35
 * @Version: v1.0
 * @Modified: 手操器默认收到数据处理策略
 * @Description: 手操器默认收到数据处理策略
 */
@Slf4j
@Service(HAND_AFTER_DEFAULT_SERVICE)
public class HandAfterDefaultService extends AbsAfterControlCommand<ModbusDto, ByteBuf> {
    public static final String HAND_AFTER_DEFAULT_SERVICE = "handAfterDefaultService";

    @Autowired
    private InstructionSendService instructionSendService;

    @Override
    public boolean afterResultJudge(AfterStrategyParam resp) {
        ControlInstructionPerformData data = new ControlInstructionPerformData();
        data.setInstruction(HexUtil.decodeHex(resp.getInstruction()));
        data.setPortKey(resp.getPortKey());
        data.setProtocols(resp.getProtocols());
        data.setAfterInstructionName(resp.getInstructionName());
        data.setDataBit(1);
        data.setChain("010101");
        instructionSendService.sendToClient(data);
        return true;
    }

}
